"""
在线学习网项目模型
"""
from django.db import models

SEX_OPTIONS=((True,'男'),(False,'女'))

# 1
class User(models.Model):
    """用户"""
    userid = models.AutoField(primary_key=True, verbose_name='用户ID')
    username = models.CharField(unique=True, max_length=20, verbose_name='用户名')
    password = models.CharField(max_length=32, verbose_name='用户密码')
    is_certificated = models.BooleanField(default=False, verbose_name='是否实名认证')
    sex = models.BooleanField(choices=SEX_OPTIONS,default=True, verbose_name='用户性别', null=True)
    balance = models.IntegerField(default=100, verbose_name='余额')
    birth = models.DateField(verbose_name='生日信息', null=True)
    tel = models.CharField(unique=True, max_length=20, verbose_name='手机号', null=True)
    city = models.CharField(max_length=10, verbose_name='城市', null=True)
    email = models.CharField(unique=True, max_length=255, verbose_name='用户邮箱',null=True)
    regdate = models.DateTimeField(auto_now_add=True, verbose_name='用户注册日期')
    point = models.IntegerField(default=0, verbose_name='用户积分')
    address = models.CharField(max_length=80, verbose_name='收货地址', null=True)
    is_locked = models.BooleanField(default=False, verbose_name='账户状态')
    photo = models.CharField(max_length=255, verbose_name='用户头像', default='')

    def __str__(self):
        return self.username

    class Meta:
        managed = True
        db_table = 'tb_user'
        verbose_name = '用户'
        verbose_name_plural = '用户'


# 2
class Idcard(models.Model):
    """身份证"""
    ino = models.AutoField(primary_key=True, verbose_name='身份信息记录ID')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid', verbose_name='所属用户')
    realname = models.CharField(max_length=20, null=False, verbose_name='真实姓名')
    idnum = models.CharField(max_length=20, null=False, verbose_name='身份证号')

    def __str__(self):
        return self.realname

    class Meta:
        managed = True
        db_table = 'tb_idcard'
        verbose_name = '身份证'
        verbose_name_plural = '身份证'


# 3
class Course(models.Model):
    """课程"""
    couid = models.AutoField(primary_key=True, verbose_name='课程ID')
    couname = models.CharField(max_length=50, verbose_name='课程名称')
    couintro = models.CharField(max_length=300, verbose_name='课程简介')
    degree = models.CharField(max_length=5, default='★☆☆☆☆', verbose_name='课程难度')
    learn_times = models.IntegerField(default=40, verbose_name='课时')
    image = models.CharField(max_length=255, default='', verbose_name='课程主图')
    stu_count = models.IntegerField(verbose_name='学习人数')
    fav_nums = models.IntegerField(verbose_name='点赞数')
    price = models.IntegerField(verbose_name='课程价格', null=False)
    tag = models.CharField(max_length=30, verbose_name='课程标签')

    def __str__(self):
        return self.couname

    class Meta:
        managed = True
        db_table = 'tb_course'
        verbose_name = '课程'
        verbose_name_plural = '课程'


# 4
class Teacher(models.Model):
    """老师"""
    teaid = models.AutoField(primary_key=True, verbose_name='老师ID')
    teaname = models.CharField(max_length=10, verbose_name='老师姓名')
    sex = models.BooleanField(choices=SEX_OPTIONS,default=True, verbose_name='老师性别')
    teaintro = models.CharField(max_length=300, verbose_name='老师介绍')
    course = models.ForeignKey(to=Course, on_delete=models.DO_NOTHING, db_column='scid', verbose_name='所属课程')

    def __str__(self):
        return self.teaname

    class Meta:
        managed = True
        db_table = 'tb_teacher'
        verbose_name = '老师'
        verbose_name_plural = '老师'


# 5
class Order(models.Model):
    """订单"""
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid', verbose_name='所属用户')
    orderid = models.AutoField(primary_key=True, verbose_name='订单号')
    couid = models.IntegerField(verbose_name='课程ID')
    goods_name = models.CharField(max_length=50, verbose_name='商品名称')
    price = models.IntegerField(verbose_name='订单金额')
    make_time = models.DateTimeField(verbose_name='订单生成时间')
    is_pay = models.BooleanField(default=False, verbose_name='是否支付')
    pay_time = models.DateTimeField(verbose_name='订单支付时间',null=True)
    pay_type = models.CharField(max_length=10, verbose_name='支付方式')
    is_deleted = models.BooleanField(verbose_name='是否删除',default=False)

    def __str__(self):
        return self.goods_name

    class Meta:
        managed = True
        db_table = 'tb_order'
        verbose_name = '订单'
        verbose_name_plural = '订单'


# 6
class Collection(models.Model):
    """收藏"""
    collid = models.AutoField(primary_key=True, verbose_name='收藏记录ID')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid',verbose_name='所属用户')
    course = models.ForeignKey(to=Course, on_delete=models.DO_NOTHING, db_column='scid',verbose_name='所属课程')

    def __str__(self):
        return self.couid

    class Meta:
        managed = True
        db_table = 'tb_collection'
        verbose_name = '收藏'
        verbose_name_plural = '收藏'


# 7
class Chapter(models.Model):
    """课程章节"""
    chaid = models.AutoField(primary_key=True, verbose_name='章节ID')
    course = models.ForeignKey(to=Course, on_delete=models.DO_NOTHING, db_column='scid',verbose_name='所属课程')
    chapterno = models.IntegerField(null=False, verbose_name='章节编号')
    vedio_name = models.CharField(max_length=50)
    vedio_url = models.CharField(max_length=255, verbose_name='视频链接', default='')

    def __str__(self):
        return self.vedio_name

    class Meta:
        managed = True
        db_table = 'tb_chapter'
        verbose_name = '课程章节'
        verbose_name_plural = '课程章节'


# 8
class Comment(models.Model):
    """用户评价"""
    commid = models.AutoField(primary_key=True, verbose_name='评价ID')
    content = models.CharField(max_length=3000, null=False, verbose_name='评价内容')
    make_time = models.DateTimeField(verbose_name='评价生成时间')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid',verbose_name='所属用户')
    username = models.CharField(max_length=20,verbose_name='用户名')
    course = models.ForeignKey(to=Course, on_delete=models.DO_NOTHING, db_column='scid',verbose_name='所属课程')

    def __str__(self):
        return self.content

    class Meta:
        managed = True
        db_table = 'tb_comment'
        verbose_name = '用户评价'
        verbose_name_plural = '用户评价'


# 9
class Sturecord(models.Model):
    """学习记录"""
    recordid = models.AutoField(primary_key=True, verbose_name='学习记录ID')
    make_time = models.DateTimeField(verbose_name='学习时间')
    is_completed = models.BooleanField(default=False,verbose_name='是否完成课程')
    user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, db_column='suid',verbose_name='所属用户')
    course = models.ForeignKey(to=Course, on_delete=models.DO_NOTHING, db_column='scid',verbose_name='所属课程')
    chapter = models.ForeignKey(to=Chapter, on_delete=models.DO_NOTHING, db_column='schid',verbose_name='所属章节')

    def __str__(self):
        return self.couid

    class Meta:
        managed = True
        db_table = 'tb_sturecoed'
        verbose_name = '学习记录'
        verbose_name_plural = '学习记录'
